﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Script.Serialization;
using DECOR.BL.BE;
using DECOR.BL.BC;
using CM.BL.BE;

namespace DECOR.Touchapp
{
    public partial class user : System.Web.UI.Page
    {
        JavaScriptSerializer jss = null;
            
        protected void Page_Load(object sender, EventArgs e)
        {
            string pRetval = string.Empty;
            Response.ContentType = "application/json; charset=UTF-8";
            if (!Request.HttpMethod.Equals("POST"))
            {
                //Salir
                //Response.Write("Invalid request");
                Response.Write("{\"success\"}");//, \"errors\":{\"reason\": \"Login failed. Try again.\" }}");
            }
            else
            {
                pRetval = "{\"success\":{0}, \"errors\":{\"reason\": \"{1}\"}}";
                RfcConfigParametersBE UsuarioWeb = new RfcConfigParametersBE();
                UsuarioWeb.UsuarioWEB = Request.Params["Usuario"];
                UsuarioWeb.PasswordWEB = Request.Params["newPassword"];
                //--cargar info de usuario a CredencialesController
                CredencialesController.cargarInfo(Request.Params); //(SIEMPRE)
                //-------------------------------------------------
                string pval = UsuarioBC.Instance.actualizar(UsuarioWeb);
                if (!string.IsNullOrEmpty(pval))
                {
                    if (pval.Substring(0, 1) == "S")
                    {
                        pRetval = pRetval.Replace("{0}", "true");
                    }
                    else
                    {
                        pRetval = pRetval.Replace("{0}", "false");
                    }

                    if (pval.Length > 2 && (pval.Substring(0, 1) == "S" || pval.Substring(0, 1) == "E"))
                    {
                        pRetval = pRetval.Replace("{1}", pval.Substring(2));
                    }
                    else
                    {
                        pRetval = pRetval.Replace("{1}", pval);
                    }
                }
                Response.ContentType = "application/json; charset=UTF-8";
                Response.Write(pRetval);
            }
        }
    }
}
